<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
    <style>
    </style>
</head>
<body>
<div id="app">
    <table width="100%" style="text-align: center;">
        <tr>
            <th>商品编号</th>
            <th>商品名称</th>
            <th>商品单价</th>
            <th>商品数量</th>
            <th>总计</th>
        </tr>
        <tr>
            <td>1</td>
            <td>REMK60</td>
            <td>{{price}}</td>
            <td>
                <button @click="jian">-</button>
                {{num}}
                <button @click="add">+</button>
            </td>
            <td>{{sum}}</td>
        </tr>
    </table>
    <script>
        let vm =new Vue({
            el:"#app",
            data:{
                price:2599,
                num:1,
               
            },
            methods:{
                jian(){
                    this.num--
                    if (this.num<0) {
                        this.num=0
                        
                    }
                 
                },
                add(){
                    this.num++
                }
            },
            computed:{
                sum(){
                    return this.price*this.num
                }
            },
            // 注意newValue,和oldValue是必须写正确的
            watch:{
                num(newValue,oldValue){
                    console.log(newValue,oldValue);
                }
            }


        })
    </script>
</div>
</body>
</html>